<?php
require_once 'interface.php';
class mLeave
{
    use \control\interfaces;

    public string $date;
    public string $time;
    /**
     * 执行
     */

    public function __construct()
    {
        // 启用扩展
        $this->init();
        $this->date = date('Y-m-d');
        $this->time = date('Y-m-d H:i:s');
    }

    private function head($title = ""): string
    {
        $root = root;
        $version = version;
        $css = <<<EOT
	<link href="{$root}static/stylesheet/animate.min.css?v=$version" rel="stylesheet">
		<link href="{$root}static/stylesheet/m.css?v=$version" rel="stylesheet">
EOT;
        $js = <<<EOT
	<script src="{$root}static/javascript/js.js?v=$version"></script>
EOT;
        $meta = "
	<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">
	<meta name='apple-mobile-web-app-capable' content='yes'>
	<meta name='apple-mobile-web-app-status-bar-style' content='black'>
	<meta name='format-detection' content='telephone=no,email=no,adress=no'>
		";
        if (empty($title)) {
            $title = para("title");
        }
        $keywords = para("keywords");
        $description = para("description");
        return <<<EOT
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="keywords" content="$keywords">
	<meta name="description" content="$description">
	<title>$title</title>
$meta $css
	<link href="{$root}favicon.ico?v=$version" rel="Bookmark">
	<link href="{$root}favicon.ico?v=$version" rel="icon">
	<link href="{$root}favicon.ico?v=$version" rel="shortcut icon">
	<link href="{$root}favicon.ico?v=$version" rel="apple-touch-icon">
	<script src="{$root}static/javascript/jquery-1.11.2.min.js?v=$version"></script>
	<script src="{$root}static/javascript/lib.js?v=$version"></script>
	<script src="{$root}static/plugins/laydate/laydate.js?v=$version"></script>
$js
	<script>
	let root = '$root';
	</script>
</head>
<body>

EOT;
    }

    /*底部*/
    private function footer(): string
    {
        return <<<eof
<script>

function commitForm(form, url){
    //防止高频点击
    let finger = 2;
    if (finger === 2) {
        //串联表单
        var formName = form.split(",");
        var serialize = "";
        var a = "";
        for (var i = 0; i < formName.length; i++) {
            if (serialize === "") {
                a = "";
            } else {
                a = "&";
            }
            if (formName[i] !== "") {
                serialize += a + $("[name=" + formName[i] + "]").serialize();
            }
        }
        //异步提交数据
        $.post(url, serialize, function (data) {
            //console.log(data);
            if (data.code==1) {
                location.href = root+'control/mSuccess.html';
            } else {
                msg(data.warn, 'error');
            }
        }, "json");
    }
}
function msg(text, type = 'info') {
    return $.Toast(text, type, {
        fullscreen: false,
        timeout: 2000,
        progress: true,
        positionClass: "toast-top-right",
    });
}
</script>

</body>
		</html>
eof;

    }

    /*返回*/
    public function indexHtml(): string
    {
        $html = $this->contentHtml();
        //返回
        return $this->head() . $html .$this->footer();
    }

    private function contentHtml(): string
    {
        $borrowInfo = select(["name" => "borrowInfo", 'title' => '归还信息', 'option' => ['安全帽','定位卡','劳保鞋','工作服'], 'class' => 'not-arrow text-input', "value" => '','other' => "multiple style='height: 100px;'"]);//
        $downIco = root.'img/control/down_arrow.svg';
        $approach = text(array('name'=>'approach','class'=>'text-input','title'=>'请填写'));

        return <<<eof
<div class="body-content">
      <!-- 状态栏 -->
      <div class="topbar">
        <div class="topbar-text">离厂登记</div>
      </div>
      <div class="content-parent">
     
      <div style="height: 44px"></div>
         <form name="visitorForm">
         <div class="row-li">
            <div class="row-li-title">输入身份证号</div>
            <div class="row-li-value"><input name="idNum" type="text" placeholder="请填写" value="" class="text-input"></div>
        </div>
        <div class="row-li" style="height: 100px;">
            <div class="row-li-title">归还信息</div>
            <div class="row-li-value">$borrowInfo<img class="row-li-icon" src="$downIco"></div>
        </div>
        <div class="row-li">
            <div class="row-li-title">离场装载</div>
            <div class="row-li-value">$approach</div>
        </div>
      </div>
      <div class="text-button" onclick="commitForm('visitorForm',root+'interface/v1/index.php?cla=visitApp&fun=leaveEdit')">确认提交</div>
    </div>
eof;
    }

}

//实例化对象
$mVisitorClass = new mLeave();
//打印结果
echo $mVisitorClass->indexHtml();

